Using OLR
vclust <- varclus (~angle+brick+wood+mixed+ density+EN +TC + TC_mature_soil + TC_saprolite_soil + TC_weath_rock + TC_unstable_structure + T_construction + spring + landfill + garbage + crack + leaning_wall + scars + downward_floor + tilted + fracture + conc_rainfall + wastewater + leak + septic_tank + tree + ground_veg + deforestation + banana + drainage , data=train.data)
# took out density since training has 0 d4 and it was not allowing do the plot
p <- plot(vclust)
par(mfrow=c(6,5))
plot.xmean.ordinaly (risk~angle+brick+wood+mixed+ density+EN +TC + TC_mature_soil + TC_saprolite_soil + TC_weath_rock + TC_unstable_structure + T_construction + spring + landfill + garbage + crack + leaning_wall + scars + downward_floor + tilted + fracture + conc_rainfall + wastewater + leak + septic_tank + tree + ground_veg + deforestation + banana + drainage, data=train.data, cr=TRUE , subn=FALSE)
#angle + building+density+EN +TC + TC_mature_Soil + TC_saprolito + TC_weath_rock + TC_rock + TC_geol_desfav + Taterro + DepEncNatural + DepTaludeAterro + DepTaludeCorte + DepTaludeAterro + aterro + lixo + entulho + crack + belly_wall + scars + drawback + tilted + fracture + conc_rainfall_water + wastewater + leak + septic_tank + drainage + tree + ground_veg + deforestation + banana
Diagnostic 2: Proportion (-5% of one of the parameters based on what is expected. Since some parameters have 2 predictors, others 5)
#library(plyr)
brick <- count(train.data$brick) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "brick")
wood <- count(train.data$wood) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "wood")
mixed <- count(train.data$mixed) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "mixed")
TC_mature_soil <- count(train.data$TC_mature_soil) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "TC_mature_soil")
T_construction <- count(train.data$T_construction ) %>%
mutate ("Percentage"=(freq/265)*100) %>%
mutate("Classifier" = "T_construction ")
spring <- count(train.data$spring) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "spring")
landfill <- count(train.data$landfill) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "landfill")
garbage <- count(train.data$garbage) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "garbage")
crack <- count(train.data$crack) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "crack")
leaning_wall <- count(train.data$leaning_wall) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "leaning_wall")
scars <- count(train.data$scars) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "DepTaludeAterro")
downward_floor <- count(train.data$downward_floor) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "scars")
tilted <- count(train.data$tilted) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "tilted")
conc_rainfall <- count(train.data$conc_rainfall) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "conc_rainfall")
wastewater <- count(train.data$wastewater) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "wastewater")
leak <- count(train.data$leak) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "conc_rainfall_water")
septic_tank <- count(train.data$septic_tank) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "septic_tank")
angle <- count(train.data$angle) # angle A less than 5% but the rest are okay (3,50, 91, 277, 109) Expected=106
angle <- angle %>%
mutate("Percentage"=(freq/106)*100)%>%
mutate("Classifier" = "angle")
EN <- count(train.data$EN) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "EN")
TC <- count(train.data$TC) %>%
mutate ("Percentage"=(freq/265)*100) %>%
mutate("Classifier" = "TC")
TC_saprolite_soil <- count(train.data$TC_saprolite_soil ) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "TC_saprolite_soil ")
banana <- count(train.data$banana) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "banana")
drainage <- count(train.data$drainage) %>%
mutate ("Percentage"=(freq/176.7)*100)%>%
mutate("Classifier" = "drainage")
deforestation <- count(train.data$deforestation) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "deforestation")
TC_unstable_structure <- count(train.data$TC_unstable_structure ) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "TC_unstable_structure ")
tree <- count(train.data$tree) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "tree")
ground_veg <- count(train.data$ground_veg) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "ground_veg")
density <- count(train.data$density) %>% #(79, 415, 36) # d4 =0
mutate ("Percentage"=(freq/132.5)*100)%>%
mutate("Classifier" = "density")
TC_weath_rock <- count(train.data$TC_weath_rock ) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "TC_weath_rock ")
fracture <- count(train.data$fracture) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "fracture")
df <- rbind(brick, wood, mixed, TC_mature_soil, T_construction, spring, landfill, garbage, crack, leaning_wall, scars, downward_floor, tilted, conc_rainfall, wastewater, leak, septic_tank, angle, EN, TC, TC_saprolite_soil, banana, drainage, deforestation, TC_unstable_structure, tree, ground_veg,density, TC_weath_rock, fracture)
df
## x freq Percentage Classifier
## 1 FALSE 38 14.3396226 brick
## 2 TRUE 492 185.6603774 brick
## 3 FALSE 457 172.4528302 wood
## 4 TRUE 73 27.5471698 wood
## 5 FALSE 490 184.9056604 mixed
## 6 TRUE 40 15.0943396 mixed
## 7 FALSE 256 96.6037736 TC_mature_soil
## 8 TRUE 274 103.3962264 TC_mature_soil
## 9 FALSE 209 78.8679245 T_construction
## 10 TRUE 321 121.1320755 T_construction
## 11 FALSE 512 193.2075472 spring
## 12 TRUE 18 6.7924528 spring
## 13 FALSE 320 120.7547170 landfill
## 14 TRUE 210 79.2452830 landfill
## 15 FALSE 352 132.8301887 garbage
## 16 TRUE 178 67.1698113 garbage
## 17 FALSE 437 164.9056604 crack
## 18 TRUE 93 35.0943396 crack
## 19 FALSE 501 189.0566038 leaning_wall
## 20 TRUE 29 10.9433962 leaning_wall
## 21 FALSE 330 124.5283019 DepTaludeAterro
## 22 TRUE 200 75.4716981 DepTaludeAterro
## 23 FALSE 459 173.2075472 scars
## 24 TRUE 71 26.7924528 scars
## 25 FALSE 430 162.2641509 tilted
## 26 TRUE 100 37.7358491 tilted
## 27 FALSE 17 6.4150943 conc_rainfall
## 28 TRUE 513 193.5849057 conc_rainfall
## 29 FALSE 204 76.9811321 wastewater
## 30 TRUE 326 123.0188679 wastewater
## 31 FALSE 338 127.5471698 conc_rainfall_water
## 32 TRUE 192 72.4528302 conc_rainfall_water
## 33 FALSE 526 198.4905660 septic_tank
## 34 TRUE 4 1.5094340 septic_tank
## 35 C 30 28.3018868 angle
## 36 D 130 122.6415094 angle
## 37 E 370 349.0566038 angle
## 38 FALSE 337 127.1698113 EN
## 39 TRUE 193 72.8301887 EN
## 40 FALSE 28 10.5660377 TC
## 41 TRUE 502 189.4339623 TC
## 42 FALSE 445 167.9245283 TC_saprolite_soil
## 43 TRUE 85 32.0754717 TC_saprolite_soil
## 44 FALSE 355 133.9622642 banana
## 45 TRUE 175 66.0377358 banana
## 46 Y 70 39.6151669 drainage
## 47 P 227 128.4663271 drainage
## 48 N 233 131.8619128 drainage
## 49 FALSE 494 186.4150943 deforestation
## 50 TRUE 36 13.5849057 deforestation
## 51 FALSE 518 195.4716981 TC_unstable_structure
## 52 TRUE 12 4.5283019 TC_unstable_structure
## 53 FALSE 204 76.9811321 tree
## 54 TRUE 326 123.0188679 tree
## 55 FALSE 154 58.1132075 ground_veg
## 56 TRUE 376 141.8867925 ground_veg
## 57 d1 66 49.8113208 density
## 58 d2 423 319.2452830 density
## 59 d3 41 30.9433962 density
## 60 FALSE 519 195.8490566 TC_weath_rock
## 61 TRUE 11 4.1509434 TC_weath_rock
## 62 FALSE 529 199.6226415 fracture
## 63 TRUE 1 0.3773585 fracture
TC_weath_rock, TC_rock_TC_geol_desf, fracture, TC_rock
f1 <- lrm(risk ~ building + EN + TC_saprolito + Taterro + DepEncNatural + DepTaludeAterro + DepTaludeCorte + landfill + garbage + construction_deposit + crack + leaning_wall + scars + downward_floor +tilted + conc_rainfall_water + wastewater + leak + tree + ground_veg + banana , data=train.data, x=TRUE , y=TRUE)
f1 <- lrm(risk ~ building + EN + TC_saprolito + Taterro + DepEncNatural + DepTaludeAterro + DepTaludeCorte + landfill + garbage + construction_deposit + crack + leaning_wall + scars + downward_floor +tilted + conc_rainfall_water + wastewater + leak + tree + ground_veg + banana + septic_tank +TC_mature_Soil , data=train.data, x=TRUE , y=TRUE) print (f1 , latex =TRUE , coefs =5) stargazer(anova(f1), type=“text”, style=“default”)
# Equation 1
eq_OLR_01 <- polr(risk ~ brick+ wood+ EN + TC_mature_soil + T_construction + spring+ landfill+ leak+ garbage+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ septic_tank+ conc_rainfall+ wastewater+ ground_veg + angle + TC_saprolite_soil, data= train.data
, method = "logistic", Hess = TRUE)
ctable <- coef(summary(eq_OLR_01))
p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value
ctable <- cbind(ctable, "p value" = p )
ctable
## Value Std. Error t value p value
## brickTRUE -1.23000934 0.4483678 -2.7433044 3.041213e-03
## woodTRUE 1.47754296 0.3379025 4.3726898 6.136252e-06
## ENTRUE 0.89306822 0.3655888 2.4428218 7.286466e-03
## TC_mature_soilTRUE 0.89154757 0.2262856 3.9399214 4.075416e-05
## T_constructionTRUE 0.25595644 0.3586244 0.7137174 2.377010e-01
## springTRUE -0.28875964 0.6549612 -0.4408806 3.296497e-01
## landfillTRUE 0.28607107 0.3282531 0.8714953 1.917419e-01
## leakTRUE -0.32568687 0.2347954 -1.3871090 8.270427e-02
## garbageTRUE -0.06251049 0.2838820 -0.2201988 4.128582e-01
## crackTRUE 2.07939129 0.3184355 6.5300231 3.287978e-11
## leaning_wallTRUE 1.76143078 0.5242220 3.3600854 3.895919e-04
## scarsTRUE 3.68085510 0.3461251 10.6344647 1.030041e-26
## downward_floorTRUE 0.89483015 0.3556057 2.5163552 5.928780e-03
## tiltedTRUE 1.07445922 0.3251058 3.3049524 4.749627e-04
## septic_tankTRUE -0.16810143 1.2716056 -0.1321962 4.474146e-01
## conc_rainfallTRUE 1.90437871 0.5794016 3.2868025 5.066593e-04
## wastewaterTRUE 0.72341968 0.2401895 3.0118701 1.298218e-03
## ground_vegTRUE 0.84950619 0.2545000 3.3379414 4.220077e-04
## angleD 0.58256381 0.4842728 1.2029661 1.144947e-01
## angleE 0.81651233 0.5470472 1.4925812 6.777343e-02
## TC_saprolite_soilTRUE 0.25169902 0.2921906 0.8614207 1.945032e-01
## R1|R2 0.99571541 0.9079201 1.0966994 1.363864e-01
## R2|R3 5.33179526 0.9582739 5.5639574 1.318622e-08
## R3|R4 10.38907780 1.0513220 9.8819180 2.493457e-23
stargazer((ctable), type="text", style="default", digits = 2)
##
## ======================================================
## Value Std. Error t value p value
## ------------------------------------------------------
## brickTRUE -1.23 0.45 -2.74 0.003
## woodTRUE 1.48 0.34 4.37 0.0000
## ENTRUE 0.89 0.37 2.44 0.01
## TC_mature_soilTRUE 0.89 0.23 3.94 0.0000
## T_constructionTRUE 0.26 0.36 0.71 0.24
## springTRUE -0.29 0.65 -0.44 0.33
## landfillTRUE 0.29 0.33 0.87 0.19
## leakTRUE -0.33 0.23 -1.39 0.08
## garbageTRUE -0.06 0.28 -0.22 0.41
## crackTRUE 2.08 0.32 6.53 0
## leaning_wallTRUE 1.76 0.52 3.36 0.0004
## scarsTRUE 3.68 0.35 10.63 0
## downward_floorTRUE 0.89 0.36 2.52 0.01
## tiltedTRUE 1.07 0.33 3.30 0.0005
## septic_tankTRUE -0.17 1.27 -0.13 0.45
## conc_rainfallTRUE 1.90 0.58 3.29 0.001
## wastewaterTRUE 0.72 0.24 3.01 0.001
## ground_vegTRUE 0.85 0.25 3.34 0.0004
## angleD 0.58 0.48 1.20 0.11
## angleE 0.82 0.55 1.49 0.07
## TC_saprolite_soilTRUE 0.25 0.29 0.86 0.19
## R1| R2 1.00 0.91 1.10 0.14
## R2| R3 5.33 0.96 5.56 0
## R3| R4 10.39 1.05 9.88 0
## ------------------------------------------------------
less p-value = 0.10 (TC_saprolitoTRUE,TaterroTRUE, DepTaludeAterroTRUE,DepTaludeAterroTRUE,landfillTRUE, construction_depositTRUE, leakTRUE)
par(mfrow=c(5,4))
plot.xmean.ordinaly (risk~ brick+ wood+ EN + TC_mature_soil + T_construction + spring+ landfill+ leak+ garbage+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ septic_tank+ conc_rainfall+ wastewater+ ground_veg + angle + TC_saprolite_soil
,data=train.data, cr=TRUE , subn=FALSE , cex.lab=1.5, cex.axis=2, cex.sub=2, cex.main=2)
Equation 1
sf <- function (y) {
c('y>=1' = qlogis(mean(y>=1)),
'y>=2' = qlogis(mean(y>=2)),
'y>=3' = qlogis(mean(y>=3)),
'y>=4' = qlogis(mean(y>=4)))
}
s<-with(train.data, summary(as.numeric(risk)~brick+ wood+ EN + TC_mature_soil + T_construction + spring+ landfill+ leak+ garbage+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ septic_tank+ conc_rainfall+ wastewater+ ground_veg + angle + TC_saprolite_soil
, fun=sf))
s
## as.numeric(risk) N= 529 , 1 Missing
##
## +-----------------+---+---+----+----------+------------+----------+
## | | |N |y>=1|y>=2 |y>=3 |y>=4 |
## +-----------------+---+---+----+----------+------------+----------+
## |brick |No | 38|Inf | 2.8903718| 1.673976434|-0.6539265|
## | |Yes|491|Inf | 2.2936565|-0.110090690|-2.0703091|
## +-----------------+---+---+----+----------+------------+----------+
## |wood |No |456|Inf | 2.1875158|-0.175890666|-2.2881964|
## | |Yes| 73|Inf | 4.2766661| 1.192138347|-0.5920511|
## +-----------------+---+---+----+----------+------------+----------+
## |EN |No |336|Inf | 1.8925642|-0.536304709|-2.6107090|
## | |Yes|193|Inf | 4.1484118| 0.971350509|-1.1905498|
## +-----------------+---+---+----+----------+------------+----------+
## |TC_mature_soil |No |256|Inf | 1.8763169|-0.251314428|-2.2686835|
## | |Yes|273|Inf | 2.9957323| 0.228089975|-1.6495324|
## +-----------------+---+---+----+----------+------------+----------+
## |T_construction |No |209|Inf | 1.5697727|-0.840471895|-3.2238634|
## | |Yes|320|Inf | 3.3354460| 0.524181415|-1.4663371|
## +-----------------+---+---+----+----------+------------+----------+
## |spring |No |511|Inf | 2.2897370|-0.035228692|-2.0171228|
## | |Yes| 18|Inf | Inf| 0.955511445|-0.2231436|
## +-----------------+---+---+----+----------+------------+----------+
## |landfill |No |319|Inf | 1.8064656|-0.546093763|-2.7593435|
## | |Yes|210|Inf | 4.6443909| 0.847297860|-1.1895841|
## +-----------------+---+---+----+----------+------------+----------+
## |leak |No |337|Inf | 1.9767874|-0.341561306|-2.4011368|
## | |Yes|192|Inf | 3.4339872| 0.600773860|-1.3350011|
## +-----------------+---+---+----+----------+------------+----------+
## |garbage |No |352|Inf | 2.1118068|-0.205263126|-2.3374539|
## | |Yes|177|Inf | 2.9267394| 0.400759217|-1.3307245|
## +-----------------+---+---+----+----------+------------+----------+
## |crack |No |436|Inf | 2.1620451|-0.352220594|-2.7178783|
## | |Yes| 93|Inf | 3.8177123| 2.233592222|-0.2376717|
## +-----------------+---+---+----+----------+------------+----------+
## |leaning_wall |No |500|Inf | 2.2657445|-0.104093891|-2.0907411|
## | |Yes| 29|Inf | Inf| 2.602689685|-0.2076394|
## +-----------------+---+---+----+----------+------------+----------+
## |scars |No |329|Inf | 1.8168055|-1.290279708|-3.9858929|
## | |Yes|200|Inf | 5.2933048| 3.316780040|-0.8001193|
## +-----------------+---+---+----+----------+------------+----------+
## |downward_floor |No |458|Inf | 2.1684456|-0.299154474|-2.3195142|
## | |Yes| 71|Inf | Inf| 3.540959324|-0.4883528|
## +-----------------+---+---+----+----------+------------+----------+
## |tilted |No |429|Inf | 2.1193936|-0.411296028|-2.5524648|
## | |Yes|100|Inf | 4.5951199| 2.586689344|-0.5322168|
## +-----------------+---+---+----+----------+------------+----------+
## |septic_tank |No |525|Inf | 2.3194631|-0.011428696|-1.9221766|
## | |Yes| 4|Inf | Inf| 1.098612289|-1.0986123|
## +-----------------+---+---+----+----------+------------+----------+
## |conc_rainfall |No | 17|Inf |-0.6061358|-2.772588722| -Inf|
## | |Yes|512|Inf | 2.5818989| 0.054701136|-1.8763169|
## +-----------------+---+---+----+----------+------------+----------+
## |wastewater |No |204|Inf | 1.6094379|-0.521296924|-2.6873241|
## | |Yes|325|Inf | 3.1780538| 0.316461037|-1.5910888|
## +-----------------+---+---+----+----------+------------+----------+
## |ground_veg |No |154|Inf | 1.2611312|-1.187165686|-2.6672282|
## | |Yes|375|Inf | 3.3266949| 0.438913042|-1.6984588|
## +-----------------+---+---+----+----------+------------+----------+
## |angle |C | 30|Inf | Inf|-0.546543706|-3.3672958|
## | |D |130|Inf | 3.7455748| 1.037987667|-1.0782034|
## | |E |369|Inf | 1.9996355|-0.300340469|-2.2877700|
## +-----------------+---+---+----+----------+------------+----------+
## |TC_saprolite_soil|No |444|Inf | 2.2327613|-0.081125545|-1.9984156|
## | |Yes| 85|Inf | 3.0081548| 0.405465108|-1.5404450|
## +-----------------+---+---+----+----------+------------+----------+
## |Overall | |529|Inf | 2.3277965|-0.003780723|-1.9138903|
## +-----------------+---+---+----+----------+------------+----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=1, cex.axis=1, cex.sub=1)
f2 <- lrm(risk ~ angle + building + EN + TC_saprolito + Taterro + DepEncNatural + DepTaludeAterro + DepTaludeCorte + landfill + garbage + construction_deposit + crack + leaning_wall + scars + downward_floor +tilted + conc_rainfall_water + wastewater + leak + drainage + TC_mature_Soil + density + TC + tree +ground_veg + deforestation + banana , data=train.data, x=TRUE , y=TRUE)
stargazer(anova(f2), type="text", style="default")
eq_OLR_02 <- polr(risk ~ brick+ wood+ EN+ TC_mature_soil+ T_construction+ landfill+ leak+ garbage+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ mixed+ conc_rainfall+ wastewater+ angle+ banana+ drainage+ TC_saprolite_soil+ TC+ deforestation,
data= train.data
, method = "logistic", Hess = TRUE)
ctable <- coef(summary(eq_OLR_02))
p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value
ctable <- cbind(ctable, "p value" = p )
ctable
## Value Std. Error t value p value
## brickTRUE -1.02669046 0.5363695 -1.91414777 2.780064e-02
## woodTRUE 1.32768210 0.3591081 3.69716521 1.090102e-04
## ENTRUE 0.75195987 0.3894495 1.93082748 2.675220e-02
## TC_mature_soilTRUE 0.83948091 0.2400754 3.49673837 2.354918e-04
## T_constructionTRUE 0.34544537 0.3633729 0.95066349 1.708876e-01
## landfillTRUE 0.15897689 0.3319484 0.47892044 3.159976e-01
## leakTRUE -0.46585461 0.2394543 -1.94548472 2.585833e-02
## garbageTRUE -0.08051925 0.2914452 -0.27627580 3.911681e-01
## crackTRUE 2.18510247 0.3315992 6.58958895 2.205230e-11
## leaning_wallTRUE 1.84694552 0.5340813 3.45817297 2.719260e-04
## treeTRUE -0.27362937 0.2436246 -1.12316005 1.306848e-01
## downward_floorTRUE 0.70251607 0.3600204 1.95132311 2.550931e-02
## tiltedTRUE 1.00138910 0.3283890 3.04939896 1.146499e-03
## ground_vegTRUE 0.74562688 0.2777504 2.68452118 3.631689e-03
## scarsTRUE 3.69680165 0.3535511 10.45620273 6.862313e-26
## mixedTRUE 0.13554685 0.5377497 0.25206308 4.004962e-01
## conc_rainfallTRUE 1.53156270 0.6140868 2.49404924 6.314751e-03
## wastewaterTRUE 0.49558891 0.2516271 1.96953739 2.444571e-02
## angleD 0.38326490 0.4883057 0.78488726 2.162598e-01
## angleE 0.64406825 0.5524103 1.16592379 1.218226e-01
## bananaTRUE 0.49509010 0.2622615 1.88777296 2.952822e-02
## drainage.L 0.94462156 0.2938619 3.21450794 6.533415e-04
## drainage.Q -0.07284589 0.1913665 -0.38066164 3.517272e-01
## TC_saprolite_soilTRUE 0.22124220 0.3020933 0.73236391 2.319732e-01
## TCTRUE -0.35016330 0.5379451 -0.65092753 2.575466e-01
## deforestationTRUE 0.27128912 0.4135792 0.65595440 2.559267e-01
## R1|R2 0.01759417 1.1656514 0.01509385 4.939787e-01
## R2|R3 4.56199525 1.1849084 3.85008267 5.903898e-05
## R3|R4 9.69255339 1.2703103 7.63006767 1.173153e-14
stargazer((ctable), type="text", style="default", digits=2)
##
## ======================================================
## Value Std. Error t value p value
## ------------------------------------------------------
## brickTRUE -1.03 0.54 -1.91 0.03
## woodTRUE 1.33 0.36 3.70 0.0001
## ENTRUE 0.75 0.39 1.93 0.03
## TC_mature_soilTRUE 0.84 0.24 3.50 0.0002
## T_constructionTRUE 0.35 0.36 0.95 0.17
## landfillTRUE 0.16 0.33 0.48 0.32
## leakTRUE -0.47 0.24 -1.95 0.03
## garbageTRUE -0.08 0.29 -0.28 0.39
## crackTRUE 2.19 0.33 6.59 0
## leaning_wallTRUE 1.85 0.53 3.46 0.0003
## treeTRUE -0.27 0.24 -1.12 0.13
## downward_floorTRUE 0.70 0.36 1.95 0.03
## tiltedTRUE 1.00 0.33 3.05 0.001
## ground_vegTRUE 0.75 0.28 2.68 0.004
## scarsTRUE 3.70 0.35 10.46 0
## mixedTRUE 0.14 0.54 0.25 0.40
## conc_rainfallTRUE 1.53 0.61 2.49 0.01
## wastewaterTRUE 0.50 0.25 1.97 0.02
## angleD 0.38 0.49 0.78 0.22
## angleE 0.64 0.55 1.17 0.12
## bananaTRUE 0.50 0.26 1.89 0.03
## drainage.L 0.94 0.29 3.21 0.001
## drainage.Q -0.07 0.19 -0.38 0.35
## TC_saprolite_soilTRUE 0.22 0.30 0.73 0.23
## TCTRUE -0.35 0.54 -0.65 0.26
## deforestationTRUE 0.27 0.41 0.66 0.26
## R1| R2 0.02 1.17 0.02 0.49
## R2| R3 4.56 1.18 3.85 0.0001
## R3| R4 9.69 1.27 7.63 0
## ------------------------------------------------------
par(mfrow=c(6,4))
plot.xmean.ordinaly (risk~ brick+ wood+ EN+ TC_mature_soil+ T_construction+ landfill+ leak+ garbage+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ mixed+ conc_rainfall+ wastewater+ angle+ banana+ drainage+ TC_saprolite_soil+ TC+ deforestation
,data=train.data, cr=TRUE , subn=FALSE , cex.lab=1.5, cex.axis=4, cex.sub=4, cex.main=4)
sf <- function (y) {
c('y>=1' = qlogis(mean(y>=1)),
'y>=2' = qlogis(mean(y>=2)),
'y>=3' = qlogis(mean(y>=3)),
'y>=4' = qlogis(mean(y>=4)))
}
s<-with(train.data, summary(as.numeric(risk)~brick+ wood+ EN+ TC_mature_soil+ T_construction+ landfill+ leak+ garbage+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ mixed+ conc_rainfall+ wastewater+ angle+ banana+ drainage+ TC_saprolite_soil+ TC+ deforestation,data=train.data
, fun=sf))
s
## as.numeric(risk) N= 529 , 1 Missing
##
## +-----------------+---+---+----+----------+------------+----------+
## | | |N |y>=1|y>=2 |y>=3 |y>=4 |
## +-----------------+---+---+----+----------+------------+----------+
## |brick |No | 38|Inf | 2.8903718| 1.673976434|-0.6539265|
## | |Yes|491|Inf | 2.2936565|-0.110090690|-2.0703091|
## +-----------------+---+---+----+----------+------------+----------+
## |wood |No |456|Inf | 2.1875158|-0.175890666|-2.2881964|
## | |Yes| 73|Inf | 4.2766661| 1.192138347|-0.5920511|
## +-----------------+---+---+----+----------+------------+----------+
## |EN |No |336|Inf | 1.8925642|-0.536304709|-2.6107090|
## | |Yes|193|Inf | 4.1484118| 0.971350509|-1.1905498|
## +-----------------+---+---+----+----------+------------+----------+
## |TC_mature_soil |No |256|Inf | 1.8763169|-0.251314428|-2.2686835|
## | |Yes|273|Inf | 2.9957323| 0.228089975|-1.6495324|
## +-----------------+---+---+----+----------+------------+----------+
## |T_construction |No |209|Inf | 1.5697727|-0.840471895|-3.2238634|
## | |Yes|320|Inf | 3.3354460| 0.524181415|-1.4663371|
## +-----------------+---+---+----+----------+------------+----------+
## |landfill |No |319|Inf | 1.8064656|-0.546093763|-2.7593435|
## | |Yes|210|Inf | 4.6443909| 0.847297860|-1.1895841|
## +-----------------+---+---+----+----------+------------+----------+
## |leak |No |337|Inf | 1.9767874|-0.341561306|-2.4011368|
## | |Yes|192|Inf | 3.4339872| 0.600773860|-1.3350011|
## +-----------------+---+---+----+----------+------------+----------+
## |garbage |No |352|Inf | 2.1118068|-0.205263126|-2.3374539|
## | |Yes|177|Inf | 2.9267394| 0.400759217|-1.3307245|
## +-----------------+---+---+----+----------+------------+----------+
## |crack |No |436|Inf | 2.1620451|-0.352220594|-2.7178783|
## | |Yes| 93|Inf | 3.8177123| 2.233592222|-0.2376717|
## +-----------------+---+---+----+----------+------------+----------+
## |leaning_wall |No |500|Inf | 2.2657445|-0.104093891|-2.0907411|
## | |Yes| 29|Inf | Inf| 2.602689685|-0.2076394|
## +-----------------+---+---+----+----------+------------+----------+
## |tree |No |203|Inf | 1.7917595|-0.555747311|-2.1594842|
## | |Yes|326|Inf | 2.8397280| 0.334369186|-1.7810642|
## +-----------------+---+---+----+----------+------------+----------+
## |downward_floor |No |458|Inf | 2.1684456|-0.299154474|-2.3195142|
## | |Yes| 71|Inf | Inf| 3.540959324|-0.4883528|
## +-----------------+---+---+----+----------+------------+----------+
## |tilted |No |429|Inf | 2.1193936|-0.411296028|-2.5524648|
## | |Yes|100|Inf | 4.5951199| 2.586689344|-0.5322168|
## +-----------------+---+---+----+----------+------------+----------+
## |ground_veg |No |154|Inf | 1.2611312|-1.187165686|-2.6672282|
## | |Yes|375|Inf | 3.3266949| 0.438913042|-1.6984588|
## +-----------------+---+---+----+----------+------------+----------+
## |scars |No |329|Inf | 1.8168055|-1.290279708|-3.9858929|
## | |Yes|200|Inf | 5.2933048| 3.316780040|-0.8001193|
## +-----------------+---+---+----+----------+------------+----------+
## |mixed |No |489|Inf | 2.2891621|-0.102338713|-2.0253743|
## | |Yes| 40|Inf | 2.9444390| 1.386294361|-0.9694006|
## +-----------------+---+---+----+----------+------------+----------+
## |conc_rainfall |No | 17|Inf |-0.6061358|-2.772588722| -Inf|
## | |Yes|512|Inf | 2.5818989| 0.054701136|-1.8763169|
## +-----------------+---+---+----+----------+------------+----------+
## |wastewater |No |204|Inf | 1.6094379|-0.521296924|-2.6873241|
## | |Yes|325|Inf | 3.1780538| 0.316461037|-1.5910888|
## +-----------------+---+---+----+----------+------------+----------+
## |angle |C | 30|Inf | Inf|-0.546543706|-3.3672958|
## | |D |130|Inf | 3.7455748| 1.037987667|-1.0782034|
## | |E |369|Inf | 1.9996355|-0.300340469|-2.2877700|
## +-----------------+---+---+----+----------+------------+----------+
## |banana |No |354|Inf | 1.9785928|-0.377294231|-2.1785324|
## | |Yes|175|Inf | 3.7553692| 0.780158558|-1.4971087|
## +-----------------+---+---+----+----------+------------+----------+
## |drainage |Y | 70|Inf | 0.6505876|-2.047692843|-4.2341065|
## | |P |226|Inf | 2.5091209|-0.582284588|-2.7963428|
## | |N |233|Inf | 3.6331905| 1.104342963|-1.1984018|
## +-----------------+---+---+----+----------+------------+----------+
## |TC_saprolite_soil|No |444|Inf | 2.2327613|-0.081125545|-1.9984156|
## | |Yes| 85|Inf | 3.0081548| 0.405465108|-1.5404450|
## +-----------------+---+---+----+----------+------------+----------+
## |TC |No | 28|Inf | Inf| 1.098612289|-0.9162907|
## | |Yes|501|Inf | 2.2679496|-0.059898142|-1.9947003|
## +-----------------+---+---+----+----------+------------+----------+
## |deforestation |No |493|Inf | 2.3480475| 0.052750565|-1.8497467|
## | |Yes| 36|Inf | 2.0794415|-0.820980552|-3.5553481|
## +-----------------+---+---+----+----------+------------+----------+
## |Overall | |529|Inf | 2.3277965|-0.003780723|-1.9138903|
## +-----------------+---+---+----+----------+------------+----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=1, cex.axis=2, cex.sub=1)
f3 <- lrm(risk ~ angle +building + EN + DepTaludeAterro+ DepTaludeCorte+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ conc_rainfall_water+ wastewater+ tree + TC , data=train.data, x=TRUE , y=TRUE) stargazer(anova(f3), type=“text”, style=“default”)
# x=TRUE, y=TRUE used by resid() below
eq_OLR_03 <- polr(risk ~ wood+ TC_mature_soil+ T_construction+ landfill+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana+ drainage, data=train.data
, method = "logistic", Hess = TRUE)
ctable <- coef(summary(eq_OLR_03))
p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value
ctable <- cbind(ctable, "p value" = p )
ctable
## Value Std. Error t value p value
## woodTRUE 1.35991301 0.3326674 4.0879060 2.176422e-05
## TC_mature_soilTRUE 0.77425875 0.2247845 3.4444486 2.861127e-04
## T_constructionTRUE 0.29033617 0.2986494 0.9721639 1.654845e-01
## landfillTRUE 0.20245697 0.2941304 0.6883238 2.456244e-01
## crackTRUE 2.16094221 0.3210591 6.7306680 8.444298e-12
## leaning_wallTRUE 1.98344090 0.5332303 3.7196700 9.974160e-05
## treeTRUE -0.22457958 0.2343787 -0.9581911 1.689832e-01
## downward_floorTRUE 0.58166083 0.3491176 1.6660886 4.784789e-02
## tiltedTRUE 1.07007476 0.3226381 3.3166409 4.555331e-04
## ground_vegTRUE 0.78040616 0.2698512 2.8919866 1.914072e-03
## scarsTRUE 3.63536564 0.3462412 10.4995190 4.341068e-26
## conc_rainfallTRUE 1.54725335 0.6022297 2.5692079 5.096565e-03
## wastewaterTRUE 0.42852562 0.2423058 1.7685321 3.848599e-02
## bananaTRUE 0.52589991 0.2502686 2.1013420 1.780548e-02
## drainage.L 0.95019610 0.2862648 3.3192911 4.512314e-04
## drainage.Q -0.02802977 0.1881813 -0.1489509 4.407962e-01
## R1|R2 0.74011047 0.5938268 1.2463407 1.063197e-01
## R2|R3 5.14352621 0.6508105 7.9032627 1.358481e-15
## R3|R4 10.14786211 0.7909758 12.8295489 5.600720e-38
stargazer((ctable), type="text", style="default", digits = 2)
##
## ===================================================
## Value Std. Error t value p value
## ---------------------------------------------------
## woodTRUE 1.36 0.33 4.09 0.0000
## TC_mature_soilTRUE 0.77 0.22 3.44 0.0003
## T_constructionTRUE 0.29 0.30 0.97 0.17
## landfillTRUE 0.20 0.29 0.69 0.25
## crackTRUE 2.16 0.32 6.73 0
## leaning_wallTRUE 1.98 0.53 3.72 0.0001
## treeTRUE -0.22 0.23 -0.96 0.17
## downward_floorTRUE 0.58 0.35 1.67 0.05
## tiltedTRUE 1.07 0.32 3.32 0.0005
## ground_vegTRUE 0.78 0.27 2.89 0.002
## scarsTRUE 3.64 0.35 10.50 0
## conc_rainfallTRUE 1.55 0.60 2.57 0.01
## wastewaterTRUE 0.43 0.24 1.77 0.04
## bananaTRUE 0.53 0.25 2.10 0.02
## drainage.L 0.95 0.29 3.32 0.0005
## drainage.Q -0.03 0.19 -0.15 0.44
## R1| R2 0.74 0.59 1.25 0.11
## R2| R3 5.14 0.65 7.90 0
## R3| R4 10.15 0.79 12.83 0
## ---------------------------------------------------
#print (f3 , latex =TRUE , coefs =5)
par(mfrow=c(3,5))
plot.xmean.ordinaly (risk ~ wood+ TC_mature_soil+ T_construction+ landfill+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana+ drainage,,
data=train.data, cr=TRUE , subn=FALSE , cex.points =0.65)
sf <- function (y) {
c('y>=1' = qlogis(mean(y>=1)),
'y>=2' = qlogis(mean(y>=2)),
'y>=3' = qlogis(mean(y>=3)),
'y>=4' = qlogis(mean(y>=4)))
}
s<-with(train.data, summary(as.numeric(risk)~wood+ TC_mature_soil+ T_construction+ landfill+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana+ drainage, fun=sf))
s
## as.numeric(risk) N= 529 , 1 Missing
##
## +--------------+---+---+----+----------+------------+----------+
## | | |N |y>=1|y>=2 |y>=3 |y>=4 |
## +--------------+---+---+----+----------+------------+----------+
## |wood |No |456|Inf | 2.1875158|-0.175890666|-2.2881964|
## | |Yes| 73|Inf | 4.2766661| 1.192138347|-0.5920511|
## +--------------+---+---+----+----------+------------+----------+
## |TC_mature_soil|No |256|Inf | 1.8763169|-0.251314428|-2.2686835|
## | |Yes|273|Inf | 2.9957323| 0.228089975|-1.6495324|
## +--------------+---+---+----+----------+------------+----------+
## |T_construction|No |209|Inf | 1.5697727|-0.840471895|-3.2238634|
## | |Yes|320|Inf | 3.3354460| 0.524181415|-1.4663371|
## +--------------+---+---+----+----------+------------+----------+
## |landfill |No |319|Inf | 1.8064656|-0.546093763|-2.7593435|
## | |Yes|210|Inf | 4.6443909| 0.847297860|-1.1895841|
## +--------------+---+---+----+----------+------------+----------+
## |crack |No |436|Inf | 2.1620451|-0.352220594|-2.7178783|
## | |Yes| 93|Inf | 3.8177123| 2.233592222|-0.2376717|
## +--------------+---+---+----+----------+------------+----------+
## |leaning_wall |No |500|Inf | 2.2657445|-0.104093891|-2.0907411|
## | |Yes| 29|Inf | Inf| 2.602689685|-0.2076394|
## +--------------+---+---+----+----------+------------+----------+
## |tree |No |203|Inf | 1.7917595|-0.555747311|-2.1594842|
## | |Yes|326|Inf | 2.8397280| 0.334369186|-1.7810642|
## +--------------+---+---+----+----------+------------+----------+
## |downward_floor|No |458|Inf | 2.1684456|-0.299154474|-2.3195142|
## | |Yes| 71|Inf | Inf| 3.540959324|-0.4883528|
## +--------------+---+---+----+----------+------------+----------+
## |tilted |No |429|Inf | 2.1193936|-0.411296028|-2.5524648|
## | |Yes|100|Inf | 4.5951199| 2.586689344|-0.5322168|
## +--------------+---+---+----+----------+------------+----------+
## |ground_veg |No |154|Inf | 1.2611312|-1.187165686|-2.6672282|
## | |Yes|375|Inf | 3.3266949| 0.438913042|-1.6984588|
## +--------------+---+---+----+----------+------------+----------+
## |scars |No |329|Inf | 1.8168055|-1.290279708|-3.9858929|
## | |Yes|200|Inf | 5.2933048| 3.316780040|-0.8001193|
## +--------------+---+---+----+----------+------------+----------+
## |conc_rainfall |No | 17|Inf |-0.6061358|-2.772588722| -Inf|
## | |Yes|512|Inf | 2.5818989| 0.054701136|-1.8763169|
## +--------------+---+---+----+----------+------------+----------+
## |wastewater |No |204|Inf | 1.6094379|-0.521296924|-2.6873241|
## | |Yes|325|Inf | 3.1780538| 0.316461037|-1.5910888|
## +--------------+---+---+----+----------+------------+----------+
## |banana |No |354|Inf | 1.9785928|-0.377294231|-2.1785324|
## | |Yes|175|Inf | 3.7553692| 0.780158558|-1.4971087|
## +--------------+---+---+----+----------+------------+----------+
## |drainage |Y | 70|Inf | 0.6505876|-2.047692843|-4.2341065|
## | |P |226|Inf | 2.5091209|-0.582284588|-2.7963428|
## | |N |233|Inf | 3.6331905| 1.104342963|-1.1984018|
## +--------------+---+---+----+----------+------------+----------+
## |Overall | |529|Inf | 2.3277965|-0.003780723|-1.9138903|
## +--------------+---+---+----+----------+------------+----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=0.6, cex.axis=0.6, cex.sub=0.6)
f4 <- lrm(risk ~ building + EN
+ DepEncNatural
+ crack + leaning_wall + scars + downward_floor +tilted + conc_rainfall_water + wastewater + drainage + TC_mature_Soil + TC + +ground_veg
,data=train.data, x=TRUE , y=TRUE) # x=TRUE, y=TRUE used by resid() below #print (f4 , latex =TRUE , coefs =5) stargazer(anova(f4), type=“text”, style=“default”)
eq_OLR_04 <- polr(risk~ wood+ TC_mature_soil+ T_construction+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana+ drainage
, data= train.data
, method = "logistic", Hess = TRUE)
p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value
ctable <- coef(summary(eq_OLR_04))
ctable <- cbind(ctable, "p value" = p )
## Warning in cbind(ctable, `p value` = p): number of rows of result is not a
## multiple of vector length (arg 2)
ctable
## Value Std. Error t value p value
## woodTRUE 1.35166967 0.3317656 4.0741701 2.176422e-05
## TC_mature_soilTRUE 0.75338776 0.2226474 3.3837713 2.861127e-04
## T_constructionTRUE 0.41586308 0.2365444 1.7580762 1.654845e-01
## crackTRUE 2.17799813 0.3202647 6.8006177 2.456244e-01
## leaning_wallTRUE 1.98732218 0.5341801 3.7203227 8.444298e-12
## treeTRUE -0.23340945 0.2338978 -0.9979120 9.974160e-05
## downward_floorTRUE 0.60394229 0.3474590 1.7381687 1.689832e-01
## tiltedTRUE 1.10583488 0.3183037 3.4741506 4.784789e-02
## ground_vegTRUE 0.79280380 0.2691426 2.9456646 4.555331e-04
## scarsTRUE 3.62781314 0.3456558 10.4954489 1.914072e-03
## conc_rainfallTRUE 1.55984002 0.6028852 2.5872918 4.341068e-26
## wastewaterTRUE 0.39802182 0.2384409 1.6692682 5.096565e-03
## bananaTRUE 0.52472732 0.2502286 2.0969915 3.848599e-02
## drainage.L 0.96780556 0.2853833 3.3912486 1.780548e-02
## drainage.Q -0.02460395 0.1881032 -0.1308003 4.512314e-04
## R1|R2 0.73750157 0.5948562 1.2397981 4.407962e-01
## R2|R3 5.14063995 0.6516730 7.8883739 1.063197e-01
## R3|R4 10.13233558 0.7905484 12.8168434 1.358481e-15
stargazer((ctable), type="text", style="default", digits=2)
##
## ===================================================
## Value Std. Error t value p value
## ---------------------------------------------------
## woodTRUE 1.35 0.33 4.07 0.0000
## TC_mature_soilTRUE 0.75 0.22 3.38 0.0003
## T_constructionTRUE 0.42 0.24 1.76 0.17
## crackTRUE 2.18 0.32 6.80 0.25
## leaning_wallTRUE 1.99 0.53 3.72 0
## treeTRUE -0.23 0.23 -1.00 0.0001
## downward_floorTRUE 0.60 0.35 1.74 0.17
## tiltedTRUE 1.11 0.32 3.47 0.05
## ground_vegTRUE 0.79 0.27 2.95 0.0005
## scarsTRUE 3.63 0.35 10.50 0.002
## conc_rainfallTRUE 1.56 0.60 2.59 0
## wastewaterTRUE 0.40 0.24 1.67 0.01
## bananaTRUE 0.52 0.25 2.10 0.04
## drainage.L 0.97 0.29 3.39 0.02
## drainage.Q -0.02 0.19 -0.13 0.0005
## R1| R2 0.74 0.59 1.24 0.44
## R2| R3 5.14 0.65 7.89 0.11
## R3| R4 10.13 0.79 12.82 0
## ---------------------------------------------------
par(mfrow=c(4,4))
plot.xmean.ordinaly (risk ~ wood+ TC_mature_soil+ T_construction+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana+ drainage
,data=train.data, cr=TRUE , subn=FALSE , cex.points =0.65)
sf <- function (y) {
c('y>=1' = qlogis(mean(y>=1)),
'y>=2' = qlogis(mean(y>=2)),
'y>=3' = qlogis(mean(y>=3)),
'y>=4' = qlogis(mean(y>=4)))
}
s<-with(train.data, summary(as.numeric(risk)~wood+ TC_mature_soil+ T_construction+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana+ drainage
, fun=sf))
s
## as.numeric(risk) N= 529 , 1 Missing
##
## +--------------+---+---+----+----------+------------+----------+
## | | |N |y>=1|y>=2 |y>=3 |y>=4 |
## +--------------+---+---+----+----------+------------+----------+
## |wood |No |456|Inf | 2.1875158|-0.175890666|-2.2881964|
## | |Yes| 73|Inf | 4.2766661| 1.192138347|-0.5920511|
## +--------------+---+---+----+----------+------------+----------+
## |TC_mature_soil|No |256|Inf | 1.8763169|-0.251314428|-2.2686835|
## | |Yes|273|Inf | 2.9957323| 0.228089975|-1.6495324|
## +--------------+---+---+----+----------+------------+----------+
## |T_construction|No |209|Inf | 1.5697727|-0.840471895|-3.2238634|
## | |Yes|320|Inf | 3.3354460| 0.524181415|-1.4663371|
## +--------------+---+---+----+----------+------------+----------+
## |crack |No |436|Inf | 2.1620451|-0.352220594|-2.7178783|
## | |Yes| 93|Inf | 3.8177123| 2.233592222|-0.2376717|
## +--------------+---+---+----+----------+------------+----------+
## |leaning_wall |No |500|Inf | 2.2657445|-0.104093891|-2.0907411|
## | |Yes| 29|Inf | Inf| 2.602689685|-0.2076394|
## +--------------+---+---+----+----------+------------+----------+
## |tree |No |203|Inf | 1.7917595|-0.555747311|-2.1594842|
## | |Yes|326|Inf | 2.8397280| 0.334369186|-1.7810642|
## +--------------+---+---+----+----------+------------+----------+
## |downward_floor|No |458|Inf | 2.1684456|-0.299154474|-2.3195142|
## | |Yes| 71|Inf | Inf| 3.540959324|-0.4883528|
## +--------------+---+---+----+----------+------------+----------+
## |tilted |No |429|Inf | 2.1193936|-0.411296028|-2.5524648|
## | |Yes|100|Inf | 4.5951199| 2.586689344|-0.5322168|
## +--------------+---+---+----+----------+------------+----------+
## |ground_veg |No |154|Inf | 1.2611312|-1.187165686|-2.6672282|
## | |Yes|375|Inf | 3.3266949| 0.438913042|-1.6984588|
## +--------------+---+---+----+----------+------------+----------+
## |scars |No |329|Inf | 1.8168055|-1.290279708|-3.9858929|
## | |Yes|200|Inf | 5.2933048| 3.316780040|-0.8001193|
## +--------------+---+---+----+----------+------------+----------+
## |conc_rainfall |No | 17|Inf |-0.6061358|-2.772588722| -Inf|
## | |Yes|512|Inf | 2.5818989| 0.054701136|-1.8763169|
## +--------------+---+---+----+----------+------------+----------+
## |wastewater |No |204|Inf | 1.6094379|-0.521296924|-2.6873241|
## | |Yes|325|Inf | 3.1780538| 0.316461037|-1.5910888|
## +--------------+---+---+----+----------+------------+----------+
## |banana |No |354|Inf | 1.9785928|-0.377294231|-2.1785324|
## | |Yes|175|Inf | 3.7553692| 0.780158558|-1.4971087|
## +--------------+---+---+----+----------+------------+----------+
## |drainage |Y | 70|Inf | 0.6505876|-2.047692843|-4.2341065|
## | |P |226|Inf | 2.5091209|-0.582284588|-2.7963428|
## | |N |233|Inf | 3.6331905| 1.104342963|-1.1984018|
## +--------------+---+---+----+----------+------------+----------+
## |Overall | |529|Inf | 2.3277965|-0.003780723|-1.9138903|
## +--------------+---+---+----+----------+------------+----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=0.7, cex.axis=0.5, cex.sub=0.5)
# x=TRUE, y=TRUE used by resid() below
#print (f1 , latex =TRUE , coefs =5)
#stargazer(anova(f1), type="text", style="default")
eq_OLR_05 <- polr(risk ~ brick+ wood+ TC_mature_soil+ T_construction+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ conc_rainfall+ wastewater+ ground_veg, data= train.data
, method = "logistic", Hess = TRUE)
ctable <- coef(summary(eq_OLR_05))
p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value
ctable <- cbind(ctable, "p value" = p )
ctable
## Value Std. Error t value p value
## brickTRUE -0.9850046 0.4326272 -2.2767978 1.139915e-02
## woodTRUE 1.4450153 0.3286541 4.3967668 5.493764e-06
## TC_mature_soilTRUE 0.7720915 0.2202420 3.5056507 2.277462e-04
## T_constructionTRUE 0.4639386 0.2320871 1.9989849 2.280499e-02
## crackTRUE 2.0607687 0.3093914 6.6607181 1.362464e-11
## leaning_wallTRUE 1.7693571 0.5258046 3.3650468 3.826534e-04
## scarsTRUE 3.7125246 0.3432396 10.8161310 1.443546e-27
## downward_floorTRUE 0.8794954 0.3436356 2.5593836 5.242898e-03
## tiltedTRUE 1.2082221 0.3170486 3.8108419 6.924717e-05
## conc_rainfallTRUE 1.9189167 0.5692761 3.3708017 3.747490e-04
## wastewaterTRUE 0.5823996 0.2292793 2.5401310 5.540549e-03
## ground_vegTRUE 0.9830516 0.2412863 4.0742128 2.308513e-05
## R1|R2 0.4242758 0.7000447 0.6060697 2.722342e-01
## R2|R3 4.6406314 0.7545942 6.1498374 3.878120e-10
## R3|R4 9.5994396 0.8531531 11.2517196 1.135601e-29
stargazer((ctable), type="text", style="default", digits = 2)
##
## ===================================================
## Value Std. Error t value p value
## ---------------------------------------------------
## brickTRUE -0.99 0.43 -2.28 0.01
## woodTRUE 1.45 0.33 4.40 0.0000
## TC_mature_soilTRUE 0.77 0.22 3.51 0.0002
## T_constructionTRUE 0.46 0.23 2.00 0.02
## crackTRUE 2.06 0.31 6.66 0
## leaning_wallTRUE 1.77 0.53 3.37 0.0004
## scarsTRUE 3.71 0.34 10.82 0
## downward_floorTRUE 0.88 0.34 2.56 0.01
## tiltedTRUE 1.21 0.32 3.81 0.0001
## conc_rainfallTRUE 1.92 0.57 3.37 0.0004
## wastewaterTRUE 0.58 0.23 2.54 0.01
## ground_vegTRUE 0.98 0.24 4.07 0.0000
## R1| R2 0.42 0.70 0.61 0.27
## R2| R3 4.64 0.75 6.15 0
## R3| R4 9.60 0.85 11.25 0
## ---------------------------------------------------
par(mfrow=c(3,4))
plot.xmean.ordinaly (risk ~ brick+ wood+ TC_mature_soil+ T_construction+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ conc_rainfall+ wastewater+ ground_veg
,data=train.data, cr=TRUE , subn=FALSE , cex.points =0.65)
sf <- function (y) {
c('y>=1' = qlogis(mean(y>=1)),
'y>=2' = qlogis(mean(y>=2)),
'y>=3' = qlogis(mean(y>=3)),
'y>=4' = qlogis(mean(y>=4)))
}
s<-with(train.data, summary(as.numeric(risk)~brick+ wood+ TC_mature_soil+ T_construction+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ conc_rainfall+ wastewater+ ground_veg
, fun=sf))
s
## as.numeric(risk) N= 529 , 1 Missing
##
## +--------------+---+---+----+----------+------------+----------+
## | | |N |y>=1|y>=2 |y>=3 |y>=4 |
## +--------------+---+---+----+----------+------------+----------+
## |brick |No | 38|Inf | 2.8903718| 1.673976434|-0.6539265|
## | |Yes|491|Inf | 2.2936565|-0.110090690|-2.0703091|
## +--------------+---+---+----+----------+------------+----------+
## |wood |No |456|Inf | 2.1875158|-0.175890666|-2.2881964|
## | |Yes| 73|Inf | 4.2766661| 1.192138347|-0.5920511|
## +--------------+---+---+----+----------+------------+----------+
## |TC_mature_soil|No |256|Inf | 1.8763169|-0.251314428|-2.2686835|
## | |Yes|273|Inf | 2.9957323| 0.228089975|-1.6495324|
## +--------------+---+---+----+----------+------------+----------+
## |T_construction|No |209|Inf | 1.5697727|-0.840471895|-3.2238634|
## | |Yes|320|Inf | 3.3354460| 0.524181415|-1.4663371|
## +--------------+---+---+----+----------+------------+----------+
## |crack |No |436|Inf | 2.1620451|-0.352220594|-2.7178783|
## | |Yes| 93|Inf | 3.8177123| 2.233592222|-0.2376717|
## +--------------+---+---+----+----------+------------+----------+
## |leaning_wall |No |500|Inf | 2.2657445|-0.104093891|-2.0907411|
## | |Yes| 29|Inf | Inf| 2.602689685|-0.2076394|
## +--------------+---+---+----+----------+------------+----------+
## |scars |No |329|Inf | 1.8168055|-1.290279708|-3.9858929|
## | |Yes|200|Inf | 5.2933048| 3.316780040|-0.8001193|
## +--------------+---+---+----+----------+------------+----------+
## |downward_floor|No |458|Inf | 2.1684456|-0.299154474|-2.3195142|
## | |Yes| 71|Inf | Inf| 3.540959324|-0.4883528|
## +--------------+---+---+----+----------+------------+----------+
## |tilted |No |429|Inf | 2.1193936|-0.411296028|-2.5524648|
## | |Yes|100|Inf | 4.5951199| 2.586689344|-0.5322168|
## +--------------+---+---+----+----------+------------+----------+
## |conc_rainfall |No | 17|Inf |-0.6061358|-2.772588722| -Inf|
## | |Yes|512|Inf | 2.5818989| 0.054701136|-1.8763169|
## +--------------+---+---+----+----------+------------+----------+
## |wastewater |No |204|Inf | 1.6094379|-0.521296924|-2.6873241|
## | |Yes|325|Inf | 3.1780538| 0.316461037|-1.5910888|
## +--------------+---+---+----+----------+------------+----------+
## |ground_veg |No |154|Inf | 1.2611312|-1.187165686|-2.6672282|
## | |Yes|375|Inf | 3.3266949| 0.438913042|-1.6984588|
## +--------------+---+---+----+----------+------------+----------+
## |Overall | |529|Inf | 2.3277965|-0.003780723|-1.9138903|
## +--------------+---+---+----+----------+------------+----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=0.7, cex.axis=0.5, cex.sub=0.5)
# x=TRUE, y=TRUE used by resid() below
#print (f1 , latex =TRUE , coefs =5)
#stargazer(anova(f1), type="text", style="default")
eq_OLR_06 <- polr(risk ~ brick+ wood+ mixed+ EN+ TC+ T_construction+ landfill+ leak+ garbage+ crack+ leaning_wall+ tree+ tilted+ angle+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana, data= train.data
, method = "logistic", Hess = TRUE)
ctable <- coef(summary(eq_OLR_06))
p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value
ctable <- cbind(ctable, "p value" = p )
ctable
## Value Std. Error t value p value
## brickTRUE -1.05807442 0.5285253 -2.0019372 2.264574e-02
## woodTRUE 1.29892967 0.3386960 3.8350906 6.275900e-05
## mixedTRUE 0.57075837 0.5211950 1.0950955 1.367374e-01
## ENTRUE 0.86131656 0.3778412 2.2795728 1.131652e-02
## TCTRUE 0.20240771 0.4996893 0.4050671 3.427141e-01
## T_constructionTRUE 0.41429074 0.3459415 1.1975745 1.155413e-01
## landfillTRUE 0.20302527 0.3160274 0.6424293 2.602972e-01
## leakTRUE -0.25535721 0.2291285 -1.1144715 1.325385e-01
## garbageTRUE -0.07754272 0.2815800 -0.2753843 3.915105e-01
## crackTRUE 2.12597279 0.3234234 6.5733425 2.459905e-11
## leaning_wallTRUE 1.88483397 0.5349106 3.5236431 2.128286e-04
## treeTRUE -0.22435865 0.2344252 -0.9570587 1.692688e-01
## tiltedTRUE 1.09959958 0.3162272 3.4772453 2.532971e-04
## angleD 0.46250012 0.4808152 0.9619082 1.680478e-01
## angleE 0.74299695 0.5411633 1.3729625 8.488200e-02
## ground_vegTRUE 0.81085622 0.2660132 3.0481804 1.151158e-03
## scarsTRUE 3.75503123 0.3487101 10.7683454 2.428251e-27
## conc_rainfallTRUE 2.30702312 0.5851224 3.9428040 4.026724e-05
## wastewaterTRUE 0.58381729 0.2351919 2.4823018 6.526833e-03
## bananaTRUE 0.62345319 0.2546202 2.4485618 7.171392e-03
## R1|R2 1.27206162 1.1114680 1.1444878 1.262107e-01
## R2|R3 5.46625859 1.1478808 4.7620438 9.582105e-07
## R3|R4 10.45765911 1.2319906 8.4884242 1.047289e-17
stargazer((ctable), type="text", style="default", digits = 2)
##
## ===================================================
## Value Std. Error t value p value
## ---------------------------------------------------
## brickTRUE -1.06 0.53 -2.00 0.02
## woodTRUE 1.30 0.34 3.84 0.0001
## mixedTRUE 0.57 0.52 1.10 0.14
## ENTRUE 0.86 0.38 2.28 0.01
## TCTRUE 0.20 0.50 0.41 0.34
## T_constructionTRUE 0.41 0.35 1.20 0.12
## landfillTRUE 0.20 0.32 0.64 0.26
## leakTRUE -0.26 0.23 -1.11 0.13
## garbageTRUE -0.08 0.28 -0.28 0.39
## crackTRUE 2.13 0.32 6.57 0
## leaning_wallTRUE 1.88 0.53 3.52 0.0002
## treeTRUE -0.22 0.23 -0.96 0.17
## tiltedTRUE 1.10 0.32 3.48 0.0003
## angleD 0.46 0.48 0.96 0.17
## angleE 0.74 0.54 1.37 0.08
## ground_vegTRUE 0.81 0.27 3.05 0.001
## scarsTRUE 3.76 0.35 10.77 0
## conc_rainfallTRUE 2.31 0.59 3.94 0.0000
## wastewaterTRUE 0.58 0.24 2.48 0.01
## bananaTRUE 0.62 0.25 2.45 0.01
## R1| R2 1.27 1.11 1.14 0.13
## R2| R3 5.47 1.15 4.76 0.0000
## R3| R4 10.46 1.23 8.49 0
## ---------------------------------------------------
par(mfrow=c(5,4))
plot.xmean.ordinaly (risk ~ brick+ wood+ mixed+ EN+ TC+ T_construction+ landfill+ leak+ garbage+ crack+ leaning_wall+ tree+ tilted+ angle+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana
,data=train.data, cr=TRUE , subn=FALSE , cex.points =0.65)
sf <- function (y) {
c('y>=1' = qlogis(mean(y>=1)),
'y>=2' = qlogis(mean(y>=2)),
'y>=3' = qlogis(mean(y>=3)),
'y>=4' = qlogis(mean(y>=4)))
}
s<-with(train.data, summary(as.numeric(risk)~brick+ wood+ mixed+ EN+ TC+ T_construction+ landfill+ leak+ garbage+ crack+ leaning_wall+ tree+ tilted+ angle+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana
, fun=sf))
s
## as.numeric(risk) N= 529 , 1 Missing
##
## +--------------+---+---+----+----------+------------+----------+
## | | |N |y>=1|y>=2 |y>=3 |y>=4 |
## +--------------+---+---+----+----------+------------+----------+
## |brick |No | 38|Inf | 2.8903718| 1.673976434|-0.6539265|
## | |Yes|491|Inf | 2.2936565|-0.110090690|-2.0703091|
## +--------------+---+---+----+----------+------------+----------+
## |wood |No |456|Inf | 2.1875158|-0.175890666|-2.2881964|
## | |Yes| 73|Inf | 4.2766661| 1.192138347|-0.5920511|
## +--------------+---+---+----+----------+------------+----------+
## |mixed |No |489|Inf | 2.2891621|-0.102338713|-2.0253743|
## | |Yes| 40|Inf | 2.9444390| 1.386294361|-0.9694006|
## +--------------+---+---+----+----------+------------+----------+
## |EN |No |336|Inf | 1.8925642|-0.536304709|-2.6107090|
## | |Yes|193|Inf | 4.1484118| 0.971350509|-1.1905498|
## +--------------+---+---+----+----------+------------+----------+
## |TC |No | 28|Inf | Inf| 1.098612289|-0.9162907|
## | |Yes|501|Inf | 2.2679496|-0.059898142|-1.9947003|
## +--------------+---+---+----+----------+------------+----------+
## |T_construction|No |209|Inf | 1.5697727|-0.840471895|-3.2238634|
## | |Yes|320|Inf | 3.3354460| 0.524181415|-1.4663371|
## +--------------+---+---+----+----------+------------+----------+
## |landfill |No |319|Inf | 1.8064656|-0.546093763|-2.7593435|
## | |Yes|210|Inf | 4.6443909| 0.847297860|-1.1895841|
## +--------------+---+---+----+----------+------------+----------+
## |leak |No |337|Inf | 1.9767874|-0.341561306|-2.4011368|
## | |Yes|192|Inf | 3.4339872| 0.600773860|-1.3350011|
## +--------------+---+---+----+----------+------------+----------+
## |garbage |No |352|Inf | 2.1118068|-0.205263126|-2.3374539|
## | |Yes|177|Inf | 2.9267394| 0.400759217|-1.3307245|
## +--------------+---+---+----+----------+------------+----------+
## |crack |No |436|Inf | 2.1620451|-0.352220594|-2.7178783|
## | |Yes| 93|Inf | 3.8177123| 2.233592222|-0.2376717|
## +--------------+---+---+----+----------+------------+----------+
## |leaning_wall |No |500|Inf | 2.2657445|-0.104093891|-2.0907411|
## | |Yes| 29|Inf | Inf| 2.602689685|-0.2076394|
## +--------------+---+---+----+----------+------------+----------+
## |tree |No |203|Inf | 1.7917595|-0.555747311|-2.1594842|
## | |Yes|326|Inf | 2.8397280| 0.334369186|-1.7810642|
## +--------------+---+---+----+----------+------------+----------+
## |tilted |No |429|Inf | 2.1193936|-0.411296028|-2.5524648|
## | |Yes|100|Inf | 4.5951199| 2.586689344|-0.5322168|
## +--------------+---+---+----+----------+------------+----------+
## |angle |C | 30|Inf | Inf|-0.546543706|-3.3672958|
## | |D |130|Inf | 3.7455748| 1.037987667|-1.0782034|
## | |E |369|Inf | 1.9996355|-0.300340469|-2.2877700|
## +--------------+---+---+----+----------+------------+----------+
## |ground_veg |No |154|Inf | 1.2611312|-1.187165686|-2.6672282|
## | |Yes|375|Inf | 3.3266949| 0.438913042|-1.6984588|
## +--------------+---+---+----+----------+------------+----------+
## |scars |No |329|Inf | 1.8168055|-1.290279708|-3.9858929|
## | |Yes|200|Inf | 5.2933048| 3.316780040|-0.8001193|
## +--------------+---+---+----+----------+------------+----------+
## |conc_rainfall |No | 17|Inf |-0.6061358|-2.772588722| -Inf|
## | |Yes|512|Inf | 2.5818989| 0.054701136|-1.8763169|
## +--------------+---+---+----+----------+------------+----------+
## |wastewater |No |204|Inf | 1.6094379|-0.521296924|-2.6873241|
## | |Yes|325|Inf | 3.1780538| 0.316461037|-1.5910888|
## +--------------+---+---+----+----------+------------+----------+
## |banana |No |354|Inf | 1.9785928|-0.377294231|-2.1785324|
## | |Yes|175|Inf | 3.7553692| 0.780158558|-1.4971087|
## +--------------+---+---+----+----------+------------+----------+
## |Overall | |529|Inf | 2.3277965|-0.003780723|-1.9138903|
## +--------------+---+---+----+----------+------------+----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=0.7, cex.axis=0.5, cex.sub=0.5)
predictedLevel1 <- predict(eq_OLR_01, test.data) # predict the levels directly
predictedScores1 <- predict(eq_OLR_01, test.data, type="p")
# predict the probabilites
## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel1)
## predictedLevel1
## R1 R2 R3 R4
## R1 3 16 0 0
## R2 3 81 9 0
## R3 0 17 57 10
## R4 0 0 15 13
p1 <- mean(as.character(test.data$risk) != as.character(predictedLevel1)) #misclassification error
p1
## [1] 0.3125
predictedLevel2 <- predict(eq_OLR_02, test.data) # predict the levels directly
## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel2)
## predictedLevel2
## R1 R2 R3 R4
## R1 3 16 0 0
## R2 1 83 9 0
## R3 0 17 54 13
## R4 0 0 15 13
p2 <- mean(as.character(test.data$risk) != as.character(predictedLevel2))
p2
## [1] 0.3169643
predictedLevel3 <- predict(eq_OLR_03, test.data) # predict the levels directly
predictedScores1 <- predict(eq_OLR_03, test.data, type="p")
# predict the probabilites
## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel3)
## predictedLevel3
## R1 R2 R3 R4
## R1 3 16 0 0
## R2 2 84 7 0
## R3 0 18 56 10
## R4 0 0 13 15
p3 <- mean(as.character(test.data$risk) != as.character(predictedLevel3))
p3
## [1] 0.2946429
predictedLevel4 <- predict(eq_OLR_04, test.data) # predict the levels directly
predictedScores1 <- predict(eq_OLR_04, test.data, type="p")
# predict the probabilites
## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel4)
## predictedLevel4
## R1 R2 R3 R4
## R1 3 16 0 0
## R2 2 84 7 0
## R3 0 18 56 10
## R4 0 0 13 15
p4 <- mean(as.character(test.data$risk) != as.character(predictedLevel4))
p4
## [1] 0.2946429
predictedLevel5 <- predict(eq_OLR_05, test.data) # predict the levels directly
predictedScores5 <- predict(eq_OLR_05, test.data, type="p")
# predict the probabilites
## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel5)
## predictedLevel5
## R1 R2 R3 R4
## R1 3 16 0 0
## R2 3 81 9 0
## R3 0 16 59 9
## R4 0 0 12 16
p5 <- mean(as.character(test.data$risk) != as.character(predictedLevel5))
p5
## [1] 0.2901786
predictedLevel6 <- predict(eq_OLR_06, test.data) # predict the levels directly
predictedScores6 <- predict(eq_OLR_06, test.data, type="p")
# predict the probabilites
## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel6)
## predictedLevel6
## R1 R2 R3 R4
## R1 3 16 0 0
## R2 4 82 7 0
## R3 0 19 51 14
## R4 0 0 14 14
p6 <- mean(as.character(test.data$risk) != as.character(predictedLevel6))
p6
## [1] 0.3303571
#Table
df2 <- data.frame(
"Equations"=c(1:6),
"Predicted"=c(1-p1,
1-p2,
1-p3,
1-p4,
1-p5,
1-p6
)
)
df2
## Equations Predicted
## 1 1 0.6875000
## 2 2 0.6830357
## 3 3 0.7053571
## 4 4 0.7053571
## 5 5 0.7098214
## 6 6 0.6696429